import { Colony } from '@/bot/Colony';

declare global {
    type RoleBodyConfig = {
        [role in CreepRole]?: {
            /**
             * 体型数组
             */
            body: BodyTable;
            /**
             * 根据当前的殖民地情况，给出该角色的期望数量，或返回 `'spec'` 交给
             * 外部处理
             */
            number: (colony: Colony) => number | 'spec';
            /**
             * 默认优先级
             */
            priority?: number;
            /**
             * 名字标签
             */
            name: string;
        };
    };
}

const special = (c: Colony): 'spec' => 'spec';
const single = (c: Colony): number => 1;

const config: RoleBodyConfig = {

    // 采集 Source
    harvester: {
        body: [
            [[WORK, 2], [MOVE, 1]],                // RCL=1 快速启动的时候能量扔地上
            [[WORK, 3], [MOVE, 2]],
            [[WORK, 5], [MOVE, 3]],
            [[WORK, 6], [MOVE, 6]],
            [[WORK, 8], [CARRY, 1], [MOVE, 4]],    // RCL=5 以后使用 link，必须要有一个 CARRY
            [[WORK, 10], [CARRY, 1], [MOVE, 5]],   // todo: 支持使用 UO 强化，减少 spawn 时间
            [[WORK, 10], [CARRY, 1], [MOVE, 5]],   // 10 WORK 部件 150t 可采集完，节约一半 CPU
            [[WORK, 10], [CARRY, 1], [MOVE, 5]]
        ],
        number: special,
        priority: 6,
        name: '⛏️'
    },

    // 房间内通用运输
    transporter: {
        body: [
            [[MOVE, 2], [CARRY, 2]],
            [[MOVE, 3], [CARRY, 3]],
            [[MOVE, 5], [CARRY, 5]],
            [[MOVE, 8], [CARRY, 8]],
            [[MOVE, 10], [CARRY, 10]],
            [[MOVE, 14], [CARRY, 14]],
            [[MOVE, 18], [CARRY, 18]],
            [[MOVE, 22], [CARRY, 22]],
        ],
        number: special,
        priority: 5,
        name: '🚐'
    },

    // 升级控制器
    upgrader: {
        body: [
            [[MOVE, 2], [CARRY, 1], [WORK, 1]],
            [[MOVE, 3], [CARRY, 1], [WORK, 2]],
            [[MOVE, 4], [CARRY, 1], [WORK, 3]],
            [[MOVE, 6], [CARRY, 1], [WORK, 5]],
            [[MOVE, 9], [CARRY, 1], [WORK, 8]],
            [[MOVE, 12], [CARRY, 1], [WORK, 11]],
            [[MOVE, 18], [CARRY, 1], [WORK, 17]],
        ],
        number: colony => [1, 4, 7, 4, 3, 3, 2, 2][colony.level - 1],
        priority: 4,
        name: '💎'
    },

    // 万能工人
    worker: {
        body: [
            [[MOVE, 2], [CARRY, 1], [WORK, 1]],
            [[MOVE, 3], [CARRY, 1], [WORK, 2]],
            [[MOVE, 4], [CARRY, 1], [WORK, 3]],
            [[MOVE, 6], [CARRY, 1], [WORK, 5]],
            [[MOVE, 9], [CARRY, 1], [WORK, 8]],
            [[MOVE, 12], [CARRY, 1], [WORK, 11]],
            [[MOVE, 18], [CARRY, 1], [WORK, 17]],
        ],
        number: colony => [1, 3, 5, 3, 3, 3, 2, 2][colony.level - 1],
        priority: 4,
        name: '🚧'
    },

    // 侦察小兵
    scout: {
        body: [
            [[MOVE, 1]],
            [[MOVE, 1]],
            [[MOVE, 1]],
            [[MOVE, 1]],
            [[MOVE, 1]],
            [[MOVE, 1]],
            [[MOVE, 1]],
            [[MOVE, 1]],
            [[MOVE, 1]],
        ],
        number: colony => colony.level <= 7 ? 1 : 0,
        priority: 4,
        name: '📡'
    }
};

export default config;